﻿

<%@ Page Title="" Language="C#" MasterPageFile="~/UI/Main.Master" AutoEventWireup="true" CodeBehind="Nhatkynhapxuat.aspx.cs" Inherits="QLBH.UI.WebForm1" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="div_control">
         <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#tim_Modal" id="bt_tim">Tìm</button>
         <button id="bt_xem_chi_tiet" >Xem Chi Tiết</button>
    </div>
   
    <div id="div_show">
        <table id="div_table"  align="center" class="gridtable" >
            <thead>
                <tr>
                <td>&nbsp;Ngày&nbsp;</td>
                <td>&nbsp;Mã Phiếu Nhập&nbsp;</td>
                <td>&nbsp;Mã Phiếu Xuất&nbsp;</td>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
     </div> 

    <!-- Modal Tim -->
<div class="modal fade" id="tim_Modal" tabindex="-1" role="dialog" aria-labelledby="tim_ModalLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h4 class="modal-title" id="tim_ModalLabel">Xem nhật ký nhập - xuất</h4>
         </div>

         <div class="modal-body">
             Từ &nbsp;<input id="txt_tu_ngay" type="text" size="8" value="<%=DateTime.Now.ToString("dd/MM/yyyy") %>" />
        Đến&nbsp;<input id="txt_den_ngay" type="text" size="8"  value="<%=DateTime.Now.ToString("dd/MM/yyyy") %>"/>
         </div>

         <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal"> Close</button>
            <button type="button" class="btn btn-primary" id="click_ok_tim">OK</button>
         </div>
      </div><!-- /.modal-content -->
   </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


    <script src="slidebars/scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="slidebars/scripts/bootstrap/js/jquery.min.js"></script>

    <script type="text/javascript">

        $(document).ready(function ()
        {
           
            $('#bt_xem_chi_tiet').click(function (e)
            {
                e.preventDefault();
                window.open("Xemchitietnhapxuat.aspx?ma_phieu_nhap=" + mang_id_nhap(), '_blank');
            });

            $('#bt_tim').click(function (e) {
                e.preventDefault();
                $('#tim_Modal').on('show.bs.modal'), function (e) {
                }
            });

            $('#click_ok_tim').click(function (e) {
                XemNhatKy_func($("#txt_tu_ngay").val(), $("#txt_den_ngay").val());
                $('#tim_Modal').modal('hide');
            });

            function mang_id_nhap() {
                return $('#div_table > tbody > tr').find('td:eq(1) input:checked').map(function () { return this.value; }).get().join(',');
            }

            function mang_id_xuat() {
                return $('#div_table > tbody > tr').find('td:eq(2) input:checked').map(function () { return this.value; }).get().join(',');
            }

            function XemNhatKy_func(tu_ngay_txt,den_ngay_txt)
            {
                var DTO =
                {
                    'tu_ngay': tu_ngay_txt.split("/").reverse().join("-"),
                    'den_ngay': den_ngay_txt.split("/").reverse().join("-"),
                    'so_dong':0
                };
                $.ajax(
                {
                    type: "POST",
                    url: "../BUSINESS/Services.asmx/XemNhatKy_ser",
                    data: JSON.stringify(DTO),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data)
                    {
                        $("#div_table tbody").html('');
                        $.each($.parseJSON(data.d), function (idx, obj)
                        {
                                $("#div_table tbody").append
                                (
                                    '<tr>'+
                                    '<td>&nbsp;'+ getFDate(obj.ngay) +'&nbsp;</td>'+
                                    '<td>' + string_to_array(obj.id_nhap) + '</td>' +
                                    '<td>' + string_to_array(obj.id_xuat) + '</td>' +
                                    '</tr>'  
                                );
                        });
                        $("#div_show").show();
                    },
                    error: function (data)
                    {
                        alert(data.d);
                    }
                });
            }

            function string_to_array(string_text) {
                var result = '';
                if (string_text == null) {
                    return result;
                }
                else {
                    var res = new Array();
                    res = string_text.split("|");
                    for (var i = 0; i < res.length - 1; i++) {
                        result += '<input id="chk_check" type="checkbox" value="' + res[i] + '" />' + res[i] + '   ';
                    }
                    return result;
                }
            }

            function getFDate(dateObject) {
                var today = new Date(dateObject);
                if (dateObject == '') {
                    today = new Date();
                }
                var dd = today.getDate();
                var mm = today.getMonth() + 1; //January is 0!

                var yyyy = today.getFullYear();
                if (dd < 10) {
                    dd = '0' + dd
                }
                if (mm < 10) {
                    mm = '0' + mm
                }
                var today = dd + '/' + mm + '/' + yyyy;
                return today;
            }

            $("#txt_tu_ngay").datepicker(
                {
                    autoclose:true,
                    format: "dd/mm/yyyy"
                });

            $("#txt_den_ngay").datepicker(
                {
                    autoclose: true,
                    format: "dd/mm/yyyy"
                });

            onload = function ()
            {
                $("#div_show").hide();
            }

        });
    </script>

</asp:Content>
